$(document).ready(function() {
      
      function onSelectItem() { 
         
      } 
      
      function formatItem(row) {
         //var row = row.split("|");
         return row[1] + ", " + row[2] + ", " + row[3] + ", " + row[4];
      }                                            
      
      function formatResult(row) {
         return row[0];
      }
      
      jQuery('input#Postcode').result(function(event, data, formatted) {
            jQuery("#postresult").html( !data ? "No match!" : '<a href="#" onclick= "editzip(this)">' + data[1] +' '+ data[2] +', '+ data[3] + ", " + data[4]+'</a>');
            $("#Postcode").hide("normal");
            $("#postresult").show("normal");
      });
      
      $("#Postcode").autocomplete("http://localhost/index.php/ajax/postcode/", {
            mustMatch: true,
            max: 20,
            delay: 150,
            width: 260,
            minChars: 3, 
            matchSubset: 1, 
            matchContains: 1, 
            cacheLength: 10, 
            formatItem: formatItem,
            formatResult: formatResult,
            onSelectItem: onSelectItem, 
            selectFirst: false
      });
      
});
function clearValue(thefield){
   thefield.value = ""
} 

function editzip(thisfield){
   $("#postresult").hide("normal");
   $("#Postcode").show("normal");
}

